package 创建型模式.原型模式;

//核心概念
//		原型接口：声明克隆方法的接口
//		具体原型：实现克隆方法的类
//		客户端：通过请求原型克隆自身来创建新对象

interface IUser
{
	public IUser clone();
}

class User implements IUser
{
	String name;
	Integer age;
	
	public User(String name,Integer age)
	{
		this.name = name;
		this.age = age;
	}

	@Override
	public IUser clone() 
	{
		User user = new User(this.name,this.age);
		return user;
	}

	@Override
	public String toString() {
		return "User{" +
				"name='" + name + '\'' +
				", age=" + age +
				'}'+" hashcode="+hashCode();
	}
}

public class PrototypePattern 
{
	public static void main(String[] args) 
	{
		IUser userA = new User("zs",18);

		IUser userB = userA.clone();

		System.out.println(userA);
		System.out.println(userB);
	}
}
